package com.crm.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

@Data
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DeptTreeResult<T> implements Serializable {
    private static final String SUCCESS = "操作成功";
    private static final String ERROR = "操作失败";

    private Integer code;
    private String msg;
    private List<T> depts;
    private List<Integer> checkedKeys;


    public DeptTreeResult(Integer code, String msg, List<T> depts, List<Integer> checkedKeys) {
        this.code = code;
        this.msg = msg;
        this.depts = depts;
        this.checkedKeys = checkedKeys;
    }

    public static <T> DeptTreeResult<T> success(List<T> depts, List<Integer> checkedKeys) {
        return new DeptTreeResult<T>(200, SUCCESS, depts, checkedKeys);
    }

    public static <T> DeptTreeResult<T> success(String msg) {
        return new DeptTreeResult<T>(200, msg, null, null);
    }

    public static <T> DeptTreeResult<T> success() {
        return new DeptTreeResult<T>(200, SUCCESS, null, null);
    }

    public static <T> DeptTreeResult<T> error(List<T> depts, List<Integer> checkedKeys) {
        return new DeptTreeResult<T>(400, ERROR, depts, checkedKeys);
    }

    public static <T> DeptTreeResult<T> error(String msg) {
        return new DeptTreeResult<T>(400, msg, null, null);
    }

    public static <T> DeptTreeResult<T> error() {
        return new DeptTreeResult<T>(400, ERROR, null, null);
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setData(List<T> depts) {
        this.depts = depts;
    }

    public void setCheckedKeys(List<Integer> checkedKeys) {
        this.checkedKeys = checkedKeys;
    }
}